public class MyQueue {
    private Object[] arr;
    private int  front = 0;//队头位置
    private int rear = -1;//队尾位置
    public MyQueue(int cap){
        this.arr = new Object[cap];
    }
    public void add(Object ele){//入队
        if(this.isFull())throw new RuntimeException("队列满！不允许入队。");
        arr[++rear]=ele;
    }
    public Object poll(){//出队
        if(this.isEmpty())throw new RuntimeException("队列空！不允许出队。");
        Object ele = arr[front];
        arr[front]=null;
        front++;
        return ele;
    }
    public int size(){
        return rear-front+1;
    }
    public boolean isFull(){//是否队满
        return rear == arr.length-1;
    }
    public boolean isEmpty(){//是否队空
        return rear < front;
    }
}
